Popular Searches
Popular Course Categories
Popular Courses

Setting Up Android Virtual Devices and Emulators

Setting Up Android Virtual Devices and Emulators

Android Studio Setup and Project Configuration

Setting Up Android Virtual Devices and Emulators

Course: Android App Development

Topic: Setting Up Android Virtual Devices and Emulators

Course Link: Android App Development Course – JustAcademy

Demo Link: Register for a Free Course Demo

Website: JustAcademy Homepage


1. Introduction

Android application development requires developers to run, test, and debug applications on devices that use the Android operating system. While physical Android phones are useful for testing, developers do not always have access to devices with different screen sizes, Android versions, memory capacities, or hardware capabilities. Android Studio provides the Android Emulator to solve this problem.

An Android Emulator runs a virtual Android device on a development computer. Developers can install applications, interact with the user interface, test navigation, simulate device conditions, and inspect application behavior without needing a separate physical phone for every test.

To use the emulator, developers create an Android Virtual Device (AVD). An AVD defines the virtual device's hardware characteristics, Android system image, storage, and other configuration settings.

2. Learning Objectives

  • Understand Android Virtual Devices and Android Emulators.
  • Learn the role of Android Studio Device Manager.
  • Configure virtual hardware profiles and Android system images.
  • Create, start, stop, edit, and delete AVDs.
  • Run an Android application on a virtual device.
  • Use emulator controls to test device features and application behavior.
  • Troubleshoot common emulator startup and performance issues.

3. What Is an Android Emulator?

An Android Emulator is a software-based environment that reproduces many features of an Android device on a computer. It allows developers to run Android applications and test them in a controlled environment.

Key Features

  • Application testing: Install and execute applications without a physical phone.
  • Screen-size testing: Test layouts on different phone and tablet profiles.
  • Android-version testing: Run compatible system images with different API levels.
  • Device simulation: Simulate rotation, location, network conditions, and selected hardware features.
  • Debugging: Connect the emulator to Android Studio debugging tools.
  • Repeatable testing: Reuse virtual device configurations for consistent test scenarios.

4. What Is an Android Virtual Device (AVD)?

An Android Virtual Device is a configuration that describes the virtual Android device used by the emulator. It defines which device profile and Android system image the emulator should use.

An AVD is not the emulator application itself. The emulator is the software that runs the virtual device, while the AVD supplies its configuration.

Main Components of an AVD

Component Description Example
Hardware profile Defines the simulated device's screen and hardware characteristics. Pixel phone or tablet profile
System image Contains the Android operating system used by the virtual device. Android image for a selected API level
API level Identifies the Android platform API supported by the system image. API level matching a testing requirement
Storage Provides virtual internal storage and optional SD-card storage. App data and emulator files
Device configuration Defines settings such as orientation, graphics, and memory. Portrait orientation and graphics mode
Virtual sensors Simulates supported hardware sensors and capabilities. GPS location or accelerometer

5. Prerequisites for Setting Up an Emulator

Before creating an AVD, prepare the Android development environment.

  • Install a compatible version of Android Studio.
  • Install the Android SDK and required SDK platform tools.
  • Ensure sufficient free disk space for system images and virtual device data.
  • Check the computer's RAM and processor capabilities.
  • Ensure hardware virtualization and any required operating-system virtualization support are enabled.
  • Use a reliable internet connection when downloading system images.

Emulator performance depends on the computer's hardware, graphics drivers, operating system, and virtualization configuration. Check the official Android Emulator documentation for current system requirements.

6. Opening Device Manager in Android Studio

Device Manager is the Android Studio interface used to create and manage virtual devices.

Method 1: From an Existing Project

  1. Open Android Studio.
  2. Open your Android application project.
  3. Select View > Tool Windows > Device Manager. In many Android Studio versions, Device Manager is also accessible from the Tools menu.
  4. Locate the Virtual devices section.
  5. Click the plus icon or select the option to create a virtual device.

Method 2: From the Welcome Screen

  1. Launch Android Studio without opening a project.
  2. Open More Actions or the corresponding virtual-device option.
  3. Select Virtual Device Manager or Device Manager, depending on the Android Studio version.
  4. Choose the option to create a new virtual device.

Note: Menu labels can vary between Android Studio releases. If a menu item is unavailable, use the Device Manager entry shown by your installed version.

7. Creating an Android Virtual Device

Follow these steps to create your first AVD.

Step 1: Select a Hardware Profile

Click Create Virtual Device. The hardware selection window displays predefined device profiles.

Choose a device based on the type of application you are developing. A phone profile is suitable for most beginner projects, while tablet profiles help test larger layouts. Other profiles may be available for Android TV, Wear OS, and additional supported device categories.

  • Select a phone profile for standard mobile applications.
  • Select a tablet profile to test responsive layouts.
  • Choose a profile with the required camera, sensors, or other features when your application depends on them.

Click Next after selecting the appropriate hardware profile.

Step 2: Choose an Android System Image

A system image contains the Android operating system that will run inside the emulator. Select a system image that matches the Android version and compatibility requirements you need to test.

Image Option Purpose
Recommended image A convenient starting point for a standard development setup.
Google APIs image Provides access to supported Google APIs and Google Play services where included.
Google Play image Includes the Play Store and Google Play services when the selected image supports them.
AOSP image Provides an Android Open Source Project system image without Google's proprietary applications and services.

If a download icon appears beside a system image, download it before continuing. System images can occupy considerable disk space, so install only the images needed for your testing tasks.

Step 3: Understand API-Level Compatibility

The Android API level identifies the platform APIs available in a particular Android release. Your chosen emulator image must satisfy your application's minimum SDK requirement.

  • minSdk: The minimum Android API level on which the application is intended to run.
  • targetSdk: The API level against which the application is designed and tested for platform behavior.
  • compileSdk: The API level used to compile the application against Android APIs.

For example, if an application requires a minimum API level of 26, a system image below API level 26 cannot run it. A higher API-level image may run the application, but additional testing on older supported versions may still be necessary.

Step 4: Configure the AVD

After choosing the system image, click Next to open the configuration screen. Review the device name and other settings. Use advanced settings when you need to adjust additional characteristics.

Setting Purpose Guidance
AVD name Identifies the virtual device. Use a descriptive name, such as Pixel_API_Test.
Startup orientation Controls the initial screen orientation. Use portrait or landscape as needed.
Graphics Controls how emulator graphics are rendered. Start with Automatic; try Software if graphics compatibility problems occur.
RAM Sets the virtual device's memory allocation where configurable. Balance emulator requirements with available computer memory.
Internal storage Sets available virtual device storage where configurable. Allocate enough space for the application and test data.
Boot option Controls how the virtual device starts. Quick Boot can reuse a saved state; Cold Boot starts from a fresh boot sequence.
Camera and sensors Configures supported virtual hardware features. Enable or select appropriate features when needed.

Step 5: Finish Creating the AVD

  1. Review the device profile and system image.
  2. Confirm the AVD name and any required settings.
  3. Click Finish.
  4. Wait for Android Studio to create the virtual device.
  5. Confirm that the AVD appears in Device Manager.

8. Starting and Stopping the Emulator

Starting the Emulator

  1. Open Device Manager.
  2. Find the AVD you created.
  3. Click its launch or play icon.
  4. Wait for the Android operating system to finish starting.
  5. Unlock the virtual device if required.

The first boot may take longer because Android initializes the virtual device and prepares its state. Later starts may be faster when a saved snapshot is available.

Stopping the Emulator

Use the emulator window's close control or the stop option in Device Manager. Stop unused emulators when you need to free system resources.

9. Running an Android Application on the Emulator

After the emulator is running, you can deploy your application from Android Studio.

  1. Open the Android application project.
  2. Wait for Gradle synchronization and project indexing to complete.
  3. Start the required AVD.
  4. Select that virtual device from the deployment-target menu in Android Studio.
  5. Click Run.
  6. Allow the application to build, install, and launch.
  7. Interact with the app and verify its behavior.

If multiple devices are available, make sure the correct emulator is selected before running the project. Review the Build and Run output if compilation, installation, or startup fails.

Example: A Simple Android Activity

The following Kotlin example illustrates a basic Activity that can be launched on an emulator. It assumes the project has the appropriate Android configuration and that the Activity is declared or configured as the launcher Activity.

package com.example.emulatordemo
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val message = TextView(this)
        message.text = "Hello, Android Emulator!"
        message.textSize = 22f
        setContentView(message)
    }
}

When you run the project, the emulator should display the message if the project dependencies, manifest, and build configuration are correct. A project using Jetpack Compose or another UI framework may have a different Activity implementation.

10. Understanding Emulator Controls

The emulator includes controls for simulating common device actions. Available options vary by emulator version and device profile.

Control Use
Power Simulates turning the virtual device's screen on or off.
Volume Simulates volume-button interactions.
Rotate Changes the simulated device orientation.
Location Supplies a simulated location for location-aware application testing.
Camera Simulates supported camera input or uses an available camera source.
Network controls Simulates selected network speeds, latency, or connectivity conditions.
Screenshot Captures the current emulator display.
Extended controls Provides additional tools, such as location, sensors, and other supported features.

11. Testing Screen Rotation and Responsive Layouts

Applications should display correctly in the orientations and screen configurations they support. The emulator allows you to test how an interface responds to a change from portrait to landscape.

  1. Launch your application.
  2. Open the emulator's rotation controls or use the supported rotation shortcut.
  3. Rotate the device to landscape.
  4. Check whether text, buttons, images, and other components remain visible.
  5. Rotate back to portrait and verify the layout again.

Test different screen sizes and densities when possible. Avoid relying on a single emulator profile to validate every device layout.

12. Testing Location, Network, and Device Conditions

Location Testing

Location-aware apps can be tested by supplying a simulated location through the emulator's location controls. Verify that the application handles permission requests, location updates, unavailable location data, and changes in position correctly.

Network Testing

Use supported emulator network controls to test how your application behaves with slower connections, increased latency, or loss of connectivity. Check loading indicators, timeouts, retry behavior, and error messages.

Device State Testing

Test screen rotation, application backgrounding, app restoration, and permission changes. These checks help identify lifecycle issues and ensure that users can recover from interruptions.

13. Managing Multiple AVDs

One of the main advantages of AVDs is that you can create multiple configurations for different testing needs.

  • Create one virtual device for the minimum Android API level supported by your application.
  • Create another device for a newer Android version.
  • Use a tablet profile to inspect larger-screen layouts.
  • Use a profile with Google Play services if the application depends on them.
  • Keep descriptive names so you can quickly select the right test environment.

To modify an existing AVD, open Device Manager and select its edit option. You can duplicate an AVD when you need a similar configuration with a different system image or setting. Delete unused AVDs to recover disk space, and remember that wiping data resets the selected virtual device's stored user data.

14. Emulator Performance Optimization

Emulators can use substantial CPU, RAM, graphics, and disk resources. The following practices can improve performance:

  • Close unnecessary applications on the development computer.
  • Run only the emulator instances required for the current task.
  • Use a system image compatible with your computer's architecture and development needs.
  • Check that hardware virtualization and the recommended acceleration configuration are enabled.
  • Keep Android Studio, SDK tools, and graphics drivers appropriately updated.
  • Use Quick Boot or snapshots when suitable, and use a Cold Boot when a clean startup is required.
  • Choose reasonable virtual RAM and storage settings instead of allocating excessive resources.
  • Try a different graphics rendering mode if the emulator displays visual glitches or crashes.

15. Common Problems and Troubleshooting

Problem Possible Cause Solution
Emulator does not start Virtualization, graphics, or configuration issue. Check system requirements, virtualization settings, and emulator logs.
Emulator is very slow Insufficient memory, CPU resources, or acceleration. Close unused applications, verify acceleration, and reduce unnecessary emulator instances.
System image is unavailable Image is not installed or internet access is unavailable. Check SDK Manager, internet access, and available disk space; download the required image.
Application will not install Build failure, incompatible API level, or installation issue. Inspect Build output, check SDK compatibility, and rebuild the project.
Emulator shows a blank or frozen screen Startup snapshot, graphics, or emulator state problem. Try restarting, changing graphics mode, or performing a Cold Boot.
Application cannot access location Missing permission or no simulated location. Check runtime permissions and set a location in emulator controls.
Insufficient disk space Large system images or stored AVD data. Free disk space and remove only virtual devices or images that are no longer needed.
App fails on an older image Required API level is higher than the image supports. Use a compatible system image or adjust the app's SDK requirements when appropriate.

16. Best Practices for Emulator-Based Testing

  • Test on more than one API level when your app supports multiple Android versions.
  • Include at least one smaller-screen and one larger-screen configuration where relevant.
  • Verify permission handling and network failure behavior.
  • Use reproducible test steps and record the AVD name and API level when reporting bugs.
  • Keep test data separate from production data.
  • Do not assume an emulator reproduces every hardware-specific behavior of a real device.
  • Validate camera, Bluetooth, biometric, sensor, and performance-sensitive features on physical devices when appropriate.
  • Reset virtual device data when you need a clean test environment, but save anything important first.

17. Practical Exercise

Goal: Create an Android virtual device and run a sample application on it.

  1. Open Android Studio and launch Device Manager.
  2. Create a phone AVD with an installed Android system image.
  3. Name the AVD clearly, such as Android_Test_Device.
  4. Finish the configuration and launch the emulator.
  5. Create or open a simple Android project.
  6. Run the app on the emulator.
  7. Rotate the device and observe the layout.
  8. Take a screenshot and record the device profile and API level.
  9. Stop the emulator and start it again to observe startup behavior.

Expected Result

The virtual device should boot successfully, display the Android interface, and run the selected application. You should also be able to perform basic interactions and inspect the app in different device states.

18. Interview Questions and Answers

Q1. What is an Android Emulator?

An Android Emulator is a software tool that runs a virtual Android environment on a computer so developers can install, execute, test, and debug Android applications.

Q2. What is an Android Virtual Device?

An AVD is a configuration that defines the simulated device hardware, Android system image, and related settings used by the emulator.

Q3. What is the difference between an AVD and an emulator?

The AVD defines the virtual device configuration. The emulator is the software that runs that configured device.

Q4. What is a system image?

A system image contains the Android operating system and platform components that run inside a virtual device.

Q5. What is an API level?

An API level is a numeric identifier for the Android platform API version. It helps developers evaluate platform compatibility and select appropriate testing environments.

Q6. Why should developers use multiple AVDs?

Multiple AVDs make it possible to test different Android versions, screen sizes, and device configurations without needing a separate physical device for each configuration.

Q7. What is the purpose of Device Manager?

Device Manager allows developers to create, launch, edit, duplicate, and delete Android Virtual Devices through Android Studio.

Q8. What is the difference between Quick Boot and Cold Boot?

Quick Boot can restore a saved emulator state to reduce startup time. Cold Boot starts the virtual device through a fresh boot sequence.

Q9. Can an emulator completely replace a physical Android phone?

No. Emulators are excellent for many development and testing tasks, but physical devices are still important for verifying real hardware behavior, manufacturer-specific differences, and certain performance or sensor features.

Q10. How can you improve emulator performance?

Check virtualization and graphics configuration, close unused applications, avoid unnecessary emulator instances, and allocate resources appropriately for the computer.

19. Quick Revision Checklist

  • Understand the difference between the emulator and an AVD.
  • Know how to open Device Manager.
  • Choose an appropriate hardware profile.
  • Download and select a compatible Android system image.
  • Configure and create an AVD.
  • Launch the emulator and run an application.
  • Test orientation, location, network conditions, and app lifecycle behavior.
  • Recognize common startup, performance, and installation problems.
  • Use physical-device testing when virtual hardware is insufficient.

20. Official Learning Resources

21. Conclusion

Android Virtual Devices and Emulators provide a practical environment for developing, testing, and debugging Android applications. By learning how to select a hardware profile, choose a system image, configure an AVD, run an application, and troubleshoot common issues, developers can establish a reliable testing workflow. Combine emulator testing with physical-device testing when necessary to improve application compatibility, usability, and reliability.


Explore Android App Development Training: View the JustAcademy Android App Development Course

Book a Demo: Register for a Course Demo

Visit JustAcademy: www.justacademy.co

Previous Next
whatsapp